home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!usenet
- From: nababs@qualcomm.com (Nasser Abbasi)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ versus Ada "HELP"
- Date: 10 Feb 1996 14:49:29 GMT
- Organization: Qualcomm Inc.
- Message-ID: <4fib9p$5mc@qualcomm.com>
- References: <4fi5iu$50m@reader2.ix.netcom.com>
- NNTP-Posting-Host: nabbasi.qualcomm.com
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.93.14
-
- In article <4fi5iu$50m@reader2.ix.netcom.com>, Markr123@ix.netcom.com
- says...
- >
- >Can anyone tell me when it is better to use C++ versus Ada and why. Has
- >anyone ever seen any comparison article on this subject. It is very
- >important that I find some sort of information discribing the difference
- >and similarities. Please repost to this news group of directly to my
- >E-mail at markr123@ix.netcom.com
- >
-
- This is paper by Dr Tucker Taft on this subject.
-
- hope this helps.
-
- Nasser
-
- -------------------------------------
-
- \begin{center}
- {\bf A Comparison of Ada, C, and C++}
-
- S. Tucker Taft\\
- February 1995\\
- Copyright (C) 1995 Intermetrics, Inc.\\
- May be copied in whole or in part provided\\
- this source is credited.
- \end{center}
-
- Ada 95 and C++ are very similar in terms of expressivity, but they
- differ in important ways as well. Most fundamental is a difference in
- language design philosophy: In Ada, the building blocks of the
- language are all designed to be inherently safe and reliable, and a
- programmer who builds an abstraction using them automatically gains at
- least the same level of safety.
-
- By contrast in C++, the building blocks of the language are by default
- unsafe, though the vigilant programmer can build safer abstractions
- out of these building blocks if they proceed carefully (though
- maintaining similar vigilance during maintenance can be difficult).
-
- In other words, the fact that the Ada building blocks are both
- flexible and inherently reliable means that it takes less time and
- money for a programming team to reach the desired level of quality and
- reliability in a software system being developed in Ada, and that this
- level of quality and reliability is more likely to be retained during
- maintenance and enhancement.
-
- The following table has a more detailed comparison of the various
- features of Ada, C, and C++.
-
- {\bf 1) Separate Compilation and Library Management}
-
- Ada: An Ada compiler is required to enforce consistency and
- strong type checking across separate compilation. The concept of
- a program library is built into the language, based on separately
- compilable modules called ``library units'' whose names are part of
- a hierarchical name space.
-
- C/C++: A C/C++ compiler only enforces consistency within
- a ``translation unit'' consisting of the include files and
- source files read in a single execution of the compiler.
- Any additional consistency checking is relegated to third--party
- tools such as ``make,'' which are somewhat more susceptible
- to unintended versions skews.
-
- {\bf 2) Portability}
-
- Ada: Ada 95 is an ISO standard (ISO/IEC--8652:1995). A large Ada
- Compiler Validation Capability (ACVC) suite exists, both for Ada 83
- and Ada 95; all commercial Ada 83 compilers are fully validated. Many
- features of the language are designed to simplify the construction of
- highly portable programs. For example, numeric types may be defined
- based on the required range of values, rather than relying on the
- possible meaning of type names like ``short int.''
-
- C/C++: C is an ISO standard; C++ is a year or more from being an ISO
- standard. At the present time, C++ compilers differ dramatically in
- the level of support for the various features of the language, meaning
- that portable programs can be difficult to construct. Numeric type
- names (such as ``short int'') are hardware dependent, making it more
- difficult to create programs that are independent of a particular
- hardware platform.
-
- {\bf 3) Arrays}
-
- Ada: Arrays are ``first--class'' types in Ada. The programmer can
- specify the type and the range of indices for a given array, and the
- compiler checks at compile--time for type consistency, and at run--time
- for array bounds consistency. Assignment and slicing operations for
- arrays are provided, and the bounds of an array are automatically
- carried along as part of parameter passing.
-
- C/C++: By default, pointer arithmetic is used to provide arrays in
- C/C++, with no type or bounds checking on indexing into an array. No
- array assignment or slicing is provided. No array bounds are carried
- along on parameter passing. In C++, an array ``template'' can be used
- to provide more checking.
-
- {\bf 4) Numerics}
-
- Ada: Ada automatically detects and signals overflow for signed
- arithmetic operations. A formal accuracy model is defined for
- floating point operations, with attributes that allow the programmer
- to query the available accuracy. Numeric types may be chosen by the
- desired range or accuracy, rather than relying on target--specific
- names such as ``long float.'' Ada 95 provides wrap--around arithmetic
- via ``modular'' integer types, which include predefined operators for
- bit--wise and/or/xor/not. Distinct user--defined numeric types may be
- used to provide compile--time protection against inappropriate adding
- of ``apples'' to ``oranges'' or equivalent, or using the wrong integer
- type as an index into an array.
-
- C/C++: The effect of numeric overflow is undefined. Numeric types
- must be chosen by name, rather than by required range or accuracy.
- The compiler silently converts between any two numeric types.
-
- {\bf 5) Pointers}
-
- Ada: Ada automatically initializes pointers to null, and detects any
- uses of null pointers. Ada 95 allows pointers to declared objects;
- the compiler performs accessibility checks to ensure that dangling
- pointers are not created.
-
- C/C++: In C/C++, pointers are not default initialized, and no checking
- is performed for uses of null pointers. A pointer to a local stack
- object may be returned from a function, thereby creating a dangling
- pointer.
-
- {\bf 6) Abstraction and Object--Oriented Programming (OOP)}
-
- Ada: Ada 83 has full support for user--defined abstract data types via
- private types, encapsulation and information--hiding via packages, and
- compile--time polymorphism and type--parameterization via ``generic''
- units. Ada 95 extends this support with full inheritance and run--time
- polymorphism of types, both for private types and record types.
- Packages remain the primary structuring, modularization, and
- information--hiding construct, allowing the programmer great
- flexibility in constructing their abstractions.
-
- C/C++: C++ has full support for object--oriented programming. C has
- essentially no language support for object--oriented (or even
- ``abstraction''--oriented) programming, though judicious use of macros
- and include files can accomplish some of the goals.
- Information--hiding is tied to classes in C++. More recently, a
- separate modularization feature has been proposed for C++
- (``namespaces'') though it is not integrated with information--hiding.
-
- {\bf 7) Concurrent and Real--Time Programming}
-
- Ada: Ada includes concurrency support (multi--tasking) within the
- language. All features of the language may be used safely in
- conjunction with multiple threads of control. Specific features exist
- to support synchronization and real--time control of tasks. Ada 95
- supports both message--oriented synchronization, via the rendezvous,
- and data--oriented synchronization, via protected types. Ada 95
- provides support for asynchronous transfer of control, triggered by
- the completion of a specified time delay or by completion of an entry
- call.
-
- C/C++: There is no direct support for concurrency in C or C++. There
- are some coroutining class libraries available for C++, though the
- typical implementations of certain features of C++ (such as exception
- handling) are often not ``thread safe.''
-
- {\bf 8) Generics}
-
- Ada: Ada supports type parameterization (compile--time polymorphism)
- via generic units. The specification of a generic unit contains all
- the information needed by the user (and the compiler) to determine
- whether any given instantiation of the generic will be legal (the
- so--called generic ``contract'' model). New versions of a generic body
- can be incorporated without affecting the legality of existing
- instantiations.
-
- C/C++: C provides syntax macros. C++ includes a ``template'' facility
- which allows type parameterization. There is no formal specification
- for the formal type parameters of a C++ template, meaning that the
- legality of an instantiation depends on the particular uses of the
- formal type parameters made within the code of the functions that
- implement the template. This can result in incompatibilities when a
- new version of the implementation of a template is developed.
-
- {\bf 9) Readability}
-
- Ada: Part of the Ada ``culture'' is a strong concern for readability.
- The language encourages the use of meaningful names, and avoids use of
- cryptic special--character notations for the constructs and operators
- of the language. All composite language constructs include an
- explicit ``end,'' thereby allowing the compiler to detect most
- single--token typing errors (such as omitting a semicolon).
-
- C/C++: C and C++ make heavy use of special characters for language
- constructs and operators. Declarations of pointers, arrays of
- pointers, pointers to functions, etc., make heavy use of asterisks,
- brackets, and nested parentheses. Composite constructs do not require
- an explicit ``end,'' making single--token typing errors more likely to
- pass uncaught through the compiler.
- \newpage
-
- {\bf 10) Compatibility}
-
- Ada: Ada 95 is upward compatible with Ada 83, and its syntax and word
- order are easy for programmers familiar with Pascal, Modula, or Algol
- to understand.
-
- C/C++: C++ is largely upward compatible with C, though at a detailed
- level, some different rules apply. The syntax of C and C++ is unlike
- most other languages, and can be a source of errors (for example, the
- equality operator is ``=='' in C/C++, and a single ``='' causes an
- assignment, even when used in the test of an if--statement).
-
- {\bf 11) Exception handling}
-
- Ada: Ada supports exception handling. In Ada 95, each occurrence of
- an exception carries along information specific to the particular
- error that occurred. Failures of run--time checks are signaled by
- raising exceptions, which can then be handled just like user--defined
- exceptions.
-
- C/C++: C has no support for exception handling. In C++, exception
- handling is defined. Any kind of object can be ``thrown'' as an
- exception. There are no predefined exceptions for errors such as
- numeric overflow or null pointer dereference.
-
- {\bf 12) User--defined operators}
-
- Ada: Ada fully supports user--defined operators. They are
- automatically inherited when one type is derived from another. For
- binary operators, the left and right operands are treated
- symmetrically.
-
- C/C++: C has no support for user--defined operators. C++ supports
- user--defined operators, but because the left and right operands are
- not treated symmetrically for binary operators defined as member
- functions, most binary operators must be defined as ``friends'' of a
- class rather than as directly inheritable members of the class.
-
-
-